<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of duenoDatosxGrupo
 *
 * @author drarko
 */
class duenoDatosxGrupo extends table
{
    public $id_grupos;
    
    public function __construct($id_dueno = null) 
    {
        parent::__construct("duenoDatosxGrupo");
        if($id_dueno != null)
        {
            $this->addWhere("id_dueno", $id_dueno);
            $res = $this->select();
            $i = 0;
            
            foreach($res as $r)
            {
                $this->id_grupos[$i] = $r['id_grupo'];
                $i++;
            }
         
        }
        return $this; 
    }    
    
    public function agregar($id_dueno, $id_grupo, $id_autor)
    {
        $this->addValue("0");
        $this->addValue($id_dueno);
        $this->addValue($id_grupo);
        $this->addValue("1");  
        
        $result = $this->insert();
        
        $log = new logDuenoDatosxGrupo();
        $log->alta($id_dueno, $id_grupo, $id_autor);
        
        return $result;
    }
    
    public function listar()
    {
        $res = $this->select();
        return $res;
    }
    
    public function eliminar($id, $id_autor)
    {
        $this->addWhere("id",$id);
        $res = $this->select();
        foreach($res as $r)
        {
            $id_grupo = $r['id_grupo'];
            $id_dueno = $r['id_dueno'];
        }
        
        $log = new logDuenoDatosxGrupo();
        $log->baja($id_dueno, $id_grupo, $id_autor);
        
        return $this->borrar($id);
    }
    
}

